package com.tencreat.common.core.config;

import com.tencreat.common.core.enums.QueueEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息队列配置
 */
@Configuration
public class RabbitMqConfig {

    @Bean
    DirectExchange dictDirect() {
        return ExchangeBuilder
                .directExchange(QueueEnum.QUEUE_MESSAGE.getExchange())
                .durable(true)
                .build();
    }


    @Bean
    public Queue dictQueue() {
        return new Queue(QueueEnum.QUEUE_MESSAGE.getName());
    }

    @Bean
    Binding dictBinding(DirectExchange dictDirect,Queue dictQueue){
        return BindingBuilder
                .bind(dictQueue)
                .to(dictDirect)
                .with(QueueEnum.QUEUE_MESSAGE.getRouteKey());
    }
}
